﻿using System;
using System.Collections.Generic;

using System.Text;
using TimKen.DataAccess;
using TimKen.DataEntity;
using System.Data;

namespace TimKen.BussLogic
{
    /// <summary>
    /// 文章管理类
    /// </summary>
    public class ArticleManager
    {
        private readonly TimKen.DataAccess.ArticleDAO dal = new TimKen.DataAccess.ArticleDAO();
        public ArticleManager()
        { }
        #region  成员方法


        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int ID)
        {
            return dal.Exists(ID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public  int  Add(TimKen.DataEntity.Article model)
        {
            return  dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(TimKen.DataEntity.Article model)
        {
            dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(int ID)
        {

            dal.Delete(ID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public TimKen.DataEntity.Article GetModel(int ID)
        {

            return dal.GetModel(ID);
        }

        

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<TimKen.DataEntity.Article> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            List<TimKen.DataEntity.Article> modelList = new List<TimKen.DataEntity.Article>();
            int rowsCount = ds.Tables[0].Rows.Count;
            if (rowsCount > 0)
            {
                TimKen.DataEntity.Article model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new TimKen.DataEntity.Article();
                    if (ds.Tables[0].Rows[0]["ID"].ToString() != "")
                    {
                        model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                    }
                    model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
                    model.Content = ds.Tables[0].Rows[0]["Content"].ToString();
                    model.Author = ds.Tables[0].Rows[0]["Author"].ToString();
                    if (ds.Tables[0].Rows[0]["CreateDate"].ToString() != "")
                    {
                        model.CreateDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString());
                    }
                    if (ds.Tables[0].Rows[0]["TypeID"].ToString() != "")
                    {
                        model.TypeID = int.Parse(ds.Tables[0].Rows[0]["TypeID"].ToString());
                    }

                    if (ds.Tables[0].Rows[0]["LanguageID"].ToString() != "")
                    {
                        model.LanguageID = int.Parse(ds.Tables[0].Rows[0]["LanguageID"].ToString());
                    }
                   
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(int PageSize, int PageIndex, string strWhere)
        {
            return dal.GetList(PageSize, PageIndex, strWhere);
        }

        #endregion  成员方法
    }
}
